package com.google.gwt.gwtpages.client.message;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.gwtpages.client.page.PageRequestSession;

public class PageRequestSessionWithMessage extends PageRequestSession implements GWTMessages.Data {

	private List<GWTMessage> messages = new ArrayList<GWTMessage>();

	public PageRequestSessionWithMessage() {
		this(null);
	}

	public PageRequestSessionWithMessage(String successMessage) {
		put(GWTMessages.Data.class, this);
		messages.add(GWTMessage.success(successMessage));
	}

	/**
	 * Return all messages for this session
	 */
	public List<GWTMessage> getMessages() {
		return messages;
	}

	/**
	 * Add 1 or many messages to the session
	 * @param message the message
	 * @return this for chaining
	 */
	public PageRequestSessionWithMessage add(GWTMessage... message) {
		for (GWTMessage _message : message)
			messages.add(_message);
		return this;
	}
}
